/**
 * Created with IntelliJ IDEA.
 * Description:
 */
public class MyCircularQueue {

    public int[] elem;
    public int front;
    public int rear;
    public MyCircularQueue(int k) {
        this.elem = new int[k+1];
    }

    //入队
    public boolean enQueue(int value) {
        if(isFull()){
            return false;
        }
        this.elem[rear] = value;
        rear = (rear + 1) % elem.length;
        return true;
    }

    //出队
    public boolean deQueue() {
        if(isEmpty()){
            return false;
        }
        front = (front + 1) % elem.length;
        return true;
    }


    public int Front() {
        if(isEmpty()){
            return -1;
        }
        return this.elem[front];
    }

    public int Rear() {
        if(isEmpty()){
            return -1;
        }
        if(rear == 0){
            int size = elem.length-1;
            return elem[size];
        }else{
            return elem[rear - 1];
        }
    }

    public boolean isEmpty() {
        if(front == rear){
            return true;
        }
        return false;
    }

    public boolean isFull() {
        if((rear + 1) % elem.length == front){
            return true;
        }
        return false;
    }
}
